package com.eling.elcms.community.webapp.controller;

import com.eling.elcms.community.model.Community;
import com.eling.elcms.community.service.ICommunityManager;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CommunityController  extends BaseFormController{
    @Autowired
    private ICommunityManager communityManager;
    
    @RequestMapping("/api/community/add")
    @ResponseBody
    public Community add(@ModelAttribute Community community) {
    	return communityManager.save(community);
    }
    
    @RequestMapping("/api/community/{pkCommunity}/delete")
    @ResponseBody
    public Msg delete(@PathVariable Long pkCommunity) {
    	communityManager.remove(pkCommunity);
    	return new Msg("删除成功");
    }
    
    @RequestMapping("/api/community/update")
    @ResponseBody
    public Community update(@RequestBody Community user) {
    	return communityManager.save(user);
    }
    
    @RequestMapping("/api/community/query")
    @ResponseBody
    public List<Community> query(@ModelAttribute Community cond) {
    	return communityManager.query(cond);
    }

}
